<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;


class CommentController extends Controller
{
   public function getIndex(Request $request)
   {     
       //设置每页显示几条 
  //     $num = $request->input('num',10);
		// // 后去搜索内容
  //     $text= $request->input('why');
  //     // 判断用户是否进行搜索
  //     if($text){
  //            // $data = DB::table('user')
  //            //   ->join('answer', 'comment.aid', '=', 'answer.id')
  //            //   ->join('user', 'user.id', '=', 'answer.uid')
  //            //   ->select( 'user.*', 'answer.content','comment.*');
  //            //   // ->get();
  //            //  dd($data);
  //       }else{
            
            $data = DB::table('comment')
               ->join('answer', 'comment.aid', '=', 'answer.id')
               ->join('user', 'user.id', '=', 'answer.uid')
               ->select( 'user.name', 'answer.content','comment.*')
               // ->paginate($num);
               ->get();
      // }
      // $all = $request->all();
      //解析模板
      return view('admin.comment.index',['data'=>$data]);
   }

   public function getDel(Request $request)
    {
        //接收数据
        $id = $request->input('id');
         // dd($id);
        //删除
        $res = DB::table('comment')->where('id','=',$id)->delete();

        if($res)
        {
            return redirect('admin/comment/index')->with('success','删除成功');
        }else{
            return redirect('admin/comment/index')->with('error','删除失败');
        }
    }

     public function getEdit(Request $request)
    {
        //接收数据
        $id = $request->input('id');
         // dd($id);
        //删除
        $res = DB::table('comment')->where('id','=',$id)->get();
        // dd($res);
        
         return view('admin/comment/edit',['res'=>$res]);
       
    }


    public function getUpdate(Request $request)
    {
        $res=$request->input();
        // dd($res);

        $data = DB::table('comment')->where('id',$res['id'])->update(['contentp'=>$res['text']]);
        // dd($data);

        if($data)
        {
            return redirect('admin/comment/index')->with('success','修改成功');
        }else{
            return back()->withInput()->with('error','修改失败');
        }
    }
}
?>